import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np

data = pd.read_csv('data/data3.csv')

# 创建一个简单的销售数据
data1 = {'Date': data['ds'],
         'Sales': data['y']}

df = pd.DataFrame(data1)
print(df)

# 将日期转换为数字
df['Date'] = pd.to_datetime(df['Date'])
df['Date'] = df['Date'].dt.strftime('%Y%m%d').astype(int)
print(df)

X = np.array(df['Date']).reshape(-1, 1)
y = np.array(df['Sales'])
print(X)

print(y)

# 构建线性回归模型
model = LinearRegression()
model.fit(X, y)

# 进行销量预测
future_dates = np.array([20250105, 20250112, 20250119, 20250126]).reshape(-1, 1)
predicted_sales = model.predict(future_dates)

print(predicted_sales)

result = pd.DataFrame(
    {'Date': ['2025-01-05', '2025-01-12', '2025-01-19', '2025-01-26'], 'Predicted Sales': predicted_sales})
print(result)
